package com.jiazhong.spring;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Auther:shuXin
 */
public class TestUser {
    //使用Log4J
    Logger logger = LoggerFactory.getLogger(TestUser.class);
    @Test
    //方式一：根据id来进行获取对象
    public void test01(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");

        User user = (User) ac.getBean("user");
        user.run();
    }

    @Test
    //方式二：根据类型来进行获取对象
    //如果使用的是类型的话，那么必须保证bean.xml中的id有且只能有一个，不同名也不行
    public void test02(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        User user = ac.getBean(User.class);
        user.run();
    }
    @Test
    //方式s三：根据id和类型来进行获取对象
    public void test03(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        User user = ac.getBean("user", User.class);
        user.run();
    }

}
